$(function() {
    $('.connexion').click(function(event){
        event.preventDefault();
       
        $( "#dialog-confirm-auth" ).dialog({
            show: 'fade',
            hide:'fade',
            resizable: false,
            draggable: false,
            width:700,
            modal: true,
               
            buttons: {
                "Se créer un compte": function() {
                    location.href = "creation_compte.php";
                },
                "Fermer": function() {
                    $(".ui-dialog-titlebar").append("");
                    location.reload() ; 
                }
                
            }
                
        });
        $(".ui-dialog-titlebar").append("<img class='popup-image' src='assets/image/user.png' width='50px' style='float:left'/>");
              
    });
});
$(function() {
    $(".identification").click(function()
    {
        $("#erreur_form").fadeIn(400).html('');
        $('#erreur_form').hide();  
            
        var email = $("#email").val();
        var mdp = $("#mdp").val();
                    
        var urlenvoye = 'email='+ email + '&mdp=' + encodeURIComponent(mdp);
        if(email==='' || mdp==='')
        {
            $("#erreur_form").show();
            $("#erreur_form").fadeIn(400).html("<img class='vertical_image' src='assets/image/attention.png' width='30px' />&nbsp;&nbsp;Vous avez oublié de remplir un champs");
        }
        else
        {
            $("#chargement_form").fadeIn(400).html("<img class='vertical_image' src='assets/image/loading2.gif' width='30px' />&nbsp;&nbsp;<span class='chargement_auth' style='color:green'>Chargement ...</span>");
            $.ajax({
                type: "POST",
                url: "verifierlogin.php",
                data: urlenvoye,
                cache: false,
                success: function(html){
                    $("#chargement_form").hide();
                    $("#erreur_form").fadeIn(400).html("");
                    $("#erreur_form").append(html);
                }       
            });
        }
        return false;
    });
});

$(function() {  
    $('.deconnexion').click(function(event){
        event.preventDefault();
        
                
        $( "#dialog-confirm-deco" ).dialog({
            show: 'fade',
            hide:'fade',
            resizable: false,
            draggable: false,
            width:700,
            modal: true,
               
            buttons: {
                "Déconnexion": function() { 
                    $.ajax({
                        type: "POST",
                        url: "detruire_session.php",
                        cache: false,
                        success: function(html){
                            location.href = "index.php";  
                        }
                    });
                
                
                },
                "Fermer": function() {
                    $(".ui-dialog-titlebar").append("");
                    $( this ).dialog( "close" );
                }
                
            }
                
        });
        $(".ui-dialog-titlebar").append("<img class='popup-image' src='assets/image/deconnexion.png' width='50px' style='float:left'/>");
              
    });
});

$(function() { 
    $('.mdp_perdu').click(function(event){
        event.preventDefault();
        $( "#dialog-confirm-auth" ).dialog( "close" );
        $( "#dialog-confirm-mdp" ).dialog({
            show: 'fade',
            hide:'fade',
            resizable: false,
            draggable: false,
            width:700,
            modal: true,
               
            buttons: {
                
                "Fermer": function() {
                    $(".ui-dialog-titlebar").append("");
                    $( this ).dialog( "close" );
                }
                
            }
                
        });
        $(".ui-dialog-titlebar").append("<img class='popup-image' src='assets/image/cadenas.png' width='50px' style='float:left'/>");
              
    });     
});
  